// 新的选择图片回调函数
export default {
  name: 'xblSelectFinishV2',
  handler (option = {}, value, fileNames, extendParam, result) {
    let base64Data = JSON.parse(value)
    let res, ext
    let namesAry = fileNames.split('#')
    let mimeType = `image/png`

    if (Array.isArray(base64Data)) {
      res = []
      base64Data.forEach((b64, idx) => {
        let blobAndUrl = window.$ui.base64.toBlobAndUrl(b64, mimeType)
        let ext = namesAry[idx].substring(namesAry[idx].lastIndexOf('.') + 1)
        res.push({
          ext,
          mimeType,
          fileType: 'image',
          url: blobAndUrl.url,
          fromNative: true,
          filename: namesAry[idx],
          data: blobAndUrl.blob,
          size: blobAndUrl.blob.size
        })
      })
    } else {
      let blobAndUrl = window.$ui.base64.toBlobAndUrl(base64Data, mimeType)
      res = {
        ext,
        mimeType,
        fileType: 'image',
        url: blobAndUrl.url,
        fromNative: true,
        isRecording: true,
        filename: namesAry[0],
        data: blobAndUrl.blob,
        size: blobAndUrl.blob.size
      }
    }

    return {
      data: res,
      type: 'image',
      result
    }
  }
}
